/**
 * Copyright 2015-2016 eyaomall.cn
 * All rights reserved.
 *
 * @project
 * @author jackey
 * @version 1.0
 * @date 2016-01-06
 */
package com.eyaomall.wxmall.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.eyaomall.wxmall.common.enums.MemberCookieEnums;
import com.github.pagehelper.StringUtil;
import com.lycheeframework.core.common.cookie.SessionManager;
/**
 * 记录推广的拦截器
 * @author pro
 *
 */
public class EIdInterceptor extends HandlerInterceptorAdapter {

	private static Logger LOG = LoggerFactory.getLogger(EIdInterceptor.class);

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String eid = request.getParameter("eid");
		String shopId = request.getParameter("shopId");
		
		LOG.error("eid:" + eid);
		LOG.error("shopId:" + shopId);
		
		if(StringUtil.isNotEmpty(shopId)){
			SessionManager manager = new SessionManager(request);
			manager.setValue(MemberCookieEnums._MALL_FORM.getName(), MemberCookieEnums._MALL_FORM_SHOP_ID.getName(), shopId,true);
			manager.save(request, MemberCookieEnums._MALL_FORM.getName(),true);
		}
		
		if(StringUtil.isNotEmpty(eid)){
			request.getSession().setAttribute("eid", eid);
		}
		
		
		return true;
	}
}
